package com.chainofresponsibility.pattern.service.handler.impl;

import com.chainofresponsibility.pattern.domain.AuditInfo;
import com.chainofresponsibility.pattern.service.AuditService;
import com.chainofresponsibility.pattern.service.handler.AuditHandler;

import java.security.PublicKey;
import java.text.ParseException;
import java.util.Date;

/**
 * @author cc
 * @classname Level2AuditHandler
 * @description TODO
 * @date 2022/3/29 15:31
 */
public class Level2AuditHandler extends AuditHandler {

    private Date beginDate;
    private Date endDate;

    {
        try {
            beginDate = sdf.parse("2020-06-11 00:00:00");
            endDate = sdf.parse("2020-06-20 23:59:59");
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    public Level2AuditHandler(String levelUserId, String levelUserName) {
        super(levelUserId, levelUserName);
    }

    @Override
    public AuditInfo doAudit(String uid, String orderId, Date auditDate) {
        Date date = AuditService.queryAuditInfo(levelUserId, orderId);
        if (null == date) {
            System.out.println("待⼆级审批 负责⼈" + levelUserName);
            return new AuditInfo("0001", "单号：", orderId, " 状态：待⼆级审批负责⼈ ", levelUserName);
        }
        AuditHandler next = super.next();
        if (null == next) {
            System.out.println("二级审批完成 审批⼈" + levelUserName);
            return new AuditInfo("0000", "单号：", orderId, " 状态：⼆级审批完成", " 时间：", sdf.format(date), " 审批⼈：", levelUserName);
        }
        /*if (auditDate.before(beginDate) || auditDate.after(endDate)) {
            System.out.println("二级审批完成 审批⼈" + levelUserName);
            return new AuditInfo("0000", "单号：", orderId, " 状态：⼆级审批完成", " 时间：", sdf.format(date), " 审批⼈：", levelUserName);
        }*/
        return next.doAudit(uid, orderId, auditDate);
    }
}
